<?php
/**
 * Created by 长毋相忘c.
 * 文件用途描述 :
 * Date: 2018/2/11/011
 * Time: 19:33
 */

namespace app\api\controller\v1;


use app\api\model\Product;
use app\api\validate\Count;
use app\api\validate\IDMustBePostiveINT;
use app\lib\exception\ProductException;

class ProductController
{
    public function getRecent($count=15){
        (new Count())->goCheck();
        $products=Product::getMostRecent($count);
        if(!$products){
            throw new ProductException();
        }
        return $products;
    }

    public function getAllProductInCategory($id){
        (new IDMustBePostiveINT())->goCheck();
        $products=Product::getProductByCategoryID($id);
        if(!$products){
            throw new ProductException();
        }
        return $products;
    }

    public function getOne($id){
        (new IDMustBePostiveINT())->goCheck();
        $product=Product::getProductDetail($id);
        if(!$product){
            throw new ProductException();
        }else{
            return $product;
        }
    }

}